﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TomVanGaever.BCS.Parser
{
    public partial class BCSParserEntityPickerControl : BCSUserControl
    {

        public IEnumerable<Type> DataSource { get; set; }
        public string TypeMember { get; set; }
        
        public Type SelectedType {
            get { return lstClasses.SelectedItem as Type; } 
        }

        public void DataBind() {
            IEnumerable<Type> entities = this.DataSource.Where(t => t.GetProperties().Count() != 0).ToList();
            lstClasses.DisplayMember = this.TypeMember;
            lstClasses.DataSource = entities;    
        }

		public override string TitleText
		{
			get
			{
				lblDescription.Visible = false;
				return lblDescription.Text;
			}
		} 

        public BCSParserEntityPickerControl()
        {
            InitializeComponent();
        }

        public override string GetStatusString()
        {
            string result = "Selected entity:\t\t\t\t\t {0}";
            return string.Format(result, this.SelectedType.FullName);
        }

        private void txtFilter_TextChanged(object sender, EventArgs e)
        {
            lstClasses.DataSource = DataSource.Where(t => t.FullName.ToLower().Contains(txtFilter.Text)).ToList();
        }
    }
}
